package cs5226.model;

import java.sql.Timestamp;
import java.util.List;

import cs5226.util.StringUtil;

public class SharedPoolFreeStatistics extends Statistics {
	private double freePct;

	@Override
	public String getText() {
		return StringUtil.formatDouble(freePct);
	}

	@Override
	public Statistics aggregate(List<Statistics> statList) {
		if (statList == null || statList.size() == 0)
			return null;

		double agrVal = 0;
		for (int i = 0; i < statList.size(); i++) {
			if (statList.get(i) instanceof SharedPoolFreeStatistics) {
				agrVal += ((SharedPoolFreeStatistics) statList.get(i))
						.getFreePct();
			}
		}
		return new DictionaryCacheStatistics(statList.get(0).getTs(), agrVal
				/ statList.size());
	}

	public double getFreePct() {
		return freePct;
	}

	public void setFreePct(double freePct) {
		this.freePct = freePct;
	}

	public SharedPoolFreeStatistics(Timestamp t, double freePct) {
		super();
		setTs(t);
		this.freePct = freePct;
	}

}
